<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
				xmlns:ui="http://java.sun.com/jsf/facelets"
				xmlns:h="http://java.sun.com/jsf/html"
				xmlns:f="http://java.sun.com/jsf/core"
				xmlns:s="http://jboss.com/products/seam/taglib"
				xmlns:rich="http://richfaces.org/rich"
				template="../template.xhtml">

	<!-- content -->
	<ui:define name="content">
		<h:messages globalOnly="true" styleClass="message" id="globalMessages" />
		<h:form>
		
		<s:button action="/compras/create.seam" id="novo1" value="Nova Compra" />
		<br/><br/>
		
		<rich:simpleTogglePanel id="comprasPanel" 
			opened="true" switchType="client">
			<f:facet name="header">Compras</f:facet>
			
			<table border="0" width="50%" cellpadding="2">
				<tr>
					<td width="20%" align="right">
						Data Compra:
					</td>
					<td width="35%">
						<rich:calendar id="dataCompradt" locale="pt_BR" datePattern="dd/MM/yyyy"
		                	value="#{compraBean.data}" />
					</td>
					<td width="45%"></td>
				</tr>
				<tr>
					<td align="right">
						Produto:
					</td>
					<td>
		                <h:inputText id="produto" value="#{compraBean.nomeProduto}"
		                	size="30" />
		                <rich:suggestionbox id="produtosb" for="produto" 
		                    suggestionAction="#{compraBean.carregarProdutos}" 
		                    var="produto"
		                    width="220"
		                    height="120"
		                    fetchValue="#{produto.descricao}"
		                    minChars="3"
		                    shadowOpacity="5"
		                    border="1" 
		                    shadowDepth="5"
		                    cellpadding="1"
		                    ignoreDupResponses="true"
		                    eventsQueue="prodQueue"
		                    requestDelay="50"
		                    ajaxSingle="true">
		                    <h:column>
		                        <h:outputText value="#{produto.descricao}" />
		                    </h:column>
		                </rich:suggestionbox>
					</td>
					<td></td>
				</tr>
				<tr>
					<td></td>
					<td>
						<h:commandButton action="#{compraBean.pesquisar}" id="pesquisar" value="Pesquisar" />
					</td>
					<td></td>
				</tr>
			</table>
		</rich:simpleTogglePanel>
		</h:form>
		
		
		<s:div id="comprasResult"
			rendered="#{compraList != null and compraList.size > 0}">
		<br/>
		<h:form>
		<rich:dataTable 
			id="comprasTable" var="compra" 
			value="#{compraList}" 
			rows="20">
			<f:facet name="header">
				<rich:datascroller id="comprasTableScroller" for="comprasTable" 
					maxPages="20" style="align: right"
					renderIfSinglePage="false"
					bypassUpdates="true" pageIndexVar="pageIndex" pagesVar="pages">
				</rich:datascroller>
			</f:facet>
			
			<rich:column sortBy="#{compra.id}">
				<f:facet name="header">ID</f:facet>
           		#{compra.id}
			</rich:column>
			<rich:column width="70px" sortBy="#{compra.data}" align="center">
				<f:facet name="header">Data</f:facet>
				<h:outputText value="#{compra.data}">
					<s:convertDateTime pattern="dd/MM/yyyy" />
				</h:outputText>
			</rich:column>
			<rich:column width="200px" sortBy="#{compra.produto.descricao}">
				<f:facet name="header">Descrição</f:facet>
           		#{compra.produto.descricao}
        	</rich:column>
			<rich:column width="50px" sortBy="#{compra.preco}" align="right">
				<f:facet name="header">Preço</f:facet>
				<h:outputText value="#{compra.preco}">
					<f:convertNumber type="currency" currencySymbol="R$" maxFractionDigits="2" />
				</h:outputText>
        	</rich:column>
			<rich:column>
				<f:facet name="header">Ação</f:facet>
				<s:link id="editar" action="#{compraBean.prepararUpdate}"><h:graphicImage alt="Editar" title="Editar" url="../img/edit.png" style="border:0; margin:1px;" /></s:link>&nbsp;&nbsp;
				<s:link id="remover" action="delete"><h:graphicImage alt="Remover" title="Remover" url="../img/delete.png" style="border:0; margin:1px;" /></s:link>
			</rich:column>
			
			<f:facet name="footer">Total: #{compraList.size}</f:facet>
		</rich:dataTable>
		</h:form>
		</s:div>
		<br />
	</ui:define>
</ui:composition>
